package com.gugee.tiktok.common.model.es;

import com.gugee.tiktok.common.model.mysql.Aweme;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.springframework.util.StringUtils;


@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ESAwemeUpsertTmp {
    private long id;
    private long awemeId;
    private String awemeType;
    private String bloggerType;
    private long updateTime=System.currentTimeMillis()/1000;
    private String uniqueId;
    private long createTime;
    private long uid;
    private long musicId;
    @Mapper(componentModel = "spring")
    public interface ESAwemeMapper {
        @Mapping(source = "id", target = "id")
        @Mapping(source = "OUid", target = "uid")
        @Mapping(source = "OMusicId", target = "musicId")
        @Mapping(source = "OAwemeId", target = "awemeId")
        @Mapping(source = "bloggerType", target = "bloggerType")
        @Mapping(target = "awemeType", expression = "java(switchIfNull(dto))")
        @Mapping(source = "OCreateTime", target = "createTime")
         ESAwemeUpsertTmp mapper(Aweme dto);

        /**
         * 如果视频未分类，则暂时用播主分类代替
         * @param dto
         * @return
         */
        default String switchIfNull(Aweme dto){
            if(StringUtils.isEmpty(dto.getAwemeType())){
                return dto.getBloggerType();
            }
            return dto.getAwemeType();
        }

    }
}
